using DG.Tweening;
using UnityEngine;
namespace NL.SpriteAnimation
{
    public class OnOffSpriteRenderColor : OnOffAction
    {
        public Color SelectedColor = Color.red;

        SpriteRenderer _Target;
        Color _OldColor;
        // Start is called before the first frame update
        void Awake()
        {
            _Target = GetComponent<SpriteRenderer>();

            _OldColor = _Target != null ? _Target.color : Color.white;
        }
        Tweener _Animer;
        protected override void _On()
        {
            if (_Target == null) return;

            if (_Animer != null && _Animer.IsPlaying()) _Animer.Kill();
            _Animer = _Target.DOColor(SelectedColor, Duration).SetDelay(Delay).SetEase(AnimEase);
        }
        protected override void _Off()
        {
            if (_Target == null) return;

            if (_Animer != null && _Animer.IsPlaying()) _Animer.Kill();
            _Animer = _Target.DOColor(_OldColor, Duration * 0.5f);
        }
    }

}
